fix: guard array_position start_from underflow#22291
fix: guard array_position start_from underflow#22291Sean-Kenneth-Doherty wants to merge 2 commits into
Conversation
|
Fresh validation on the PR head (
GitHub Actions only ran the labeler for this PR, so this keeps the regression evidence visible while the branch waits for review. |
Jefffrey
left a comment
There was a problem hiding this comment.
Maybe we should use saturating sub instead? It seems we have paths later on validating it isn't negative, but only checking when the row is non-null in the input array:
datafusion/datafusion/functions-nested/src/position.rs
Lines 264 to 277 in bdf8a6d
datafusion/datafusion/functions-nested/src/position.rs
Lines 318 to 322 in bdf8a6d
Just to keep things consistent 🤔
|
Updated in I also changed the regression to exercise the full Validation:
|
| } | ||
| } | ||
|
|
||
| fn normalize_start_from(start_from: i64) -> Result<i64> { |
| use datafusion_common::config::ConfigOptions; | ||
|
|
||
| #[test] | ||
| fn test_array_position_start_from_min_value() -> Result<()> { |
There was a problem hiding this comment.
we can remove this test since we already have an SLT
Which issue does this PR close?
Rationale for this change
array_positionconverts the optional 1-indexedstart_fromargument to a 0-indexed offset by subtracting one. Whenstart_fromisi64::MIN, that subtraction can underflow and panic before DataFusion can return a normal error.What changes are included in this PR?
array_positionstart_fromvalues.start_frompaths.i64::MINboundary.Are these changes tested?
cargo fmt --allTMPDIR=/home/sean/Projects/datafusion-array-position-min/target/tmp cargo test -p datafusion-functions-nested position::tests::test_array_position_start_from_min_value -- --nocaptureTMPDIR=/home/sean/Projects/datafusion-array-position-min/target/tmp cargo test --profile=ci --test sqllogictests -- array/array_position.sltTMPDIR=/home/sean/Projects/datafusion-array-position-min/target/tmp cargo clippy --all-targets --all-features -- -D warningsgit diff --checkI also manually checked the issue reproducer no longer panics:
EXPLAIN SELECT array_position([1], 1, -9223372036854775808);now returns a plan, while plain execution returnsExecution error: start_from out of bounds: -9223372036854775808.Are there any user-facing changes?
Invalid
array_positionstart_fromvalues at thei64::MINboundary now return a normal DataFusion error instead of panicking.